package com.azunitech.apm.bundles.shell.commands;

import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import com.azunitech.apm.bundles.shell.BasicCommand;

public class CommandINST extends BasicCommand<BundleContext>
{
	private static final String CMD_INST = "inst";
	private static final String CMD_DESC = "Install a bundle with a path. file:/c:/downloads/zookeeper-3.4.5.jar";
	
	public String getKey()
	{
		return CommandINST.CMD_INST;
	}

	public String getDesc() 
	{
		return CommandINST.CMD_DESC;
	}
	
	//File myFile = new File("/sdcard/mysdfile.txt");
	//FileInputStream fIn = new FileInputStream(myFile);
	
	public void exec(String args, PrintStream out, PrintStream err) 
	{
		try 
		{
			BundleContext context = this.m_target;
			Bundle bundle;
			InputStream fIn =new URL(args.substring(5)).openStream();
			bundle = context.installBundle(args.substring(5), fIn);
		    out.println("Bundle: " + bundle.getBundleId());
		} 
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
